<?php
namespace Admin\Controller;

use Think\Controller;

class LbPictureController extends CommonController
{
    public function index()
    {
        $picture = M('lb_picture')->select();
        $this->assign('picture', $picture);
        $this->display();
    }

    //更换轮播图
    public function edit()
    {
        if(IS_POST){
           $picture['lb_picture'] = uploadPicture();
            if($picture){
               if(false === M('LbPicture')->where('id='.I('id'))->save($picture)){
                   $this->error('数据异常');
               }else{
                   $this->success('图片已更换',U('index'));
               }
            }
            $this->success('未更换图片',U('index'));
        }
        $id = I('uid');
        $info = M('LbPicture')->where('id=' . $id)->find();
        $this->assign('info',$info);
        $this->display();
    }
    
    //上传轮播图
    public function upload()
    {
        $data['lb_picture'] = uploadPicture();
        if(M('lb_picture')->add($data)){
            $this->success('添加成功',U('index'));
        }else{
            $this->error('添加失败');
        }
    }

    //删除
    public function del()
    {
        $uids = isset($_REQUEST['uid']) ? $_REQUEST['uid'] : false;
        if (is_array($uids)) {
            foreach ($uids as $k => $v) {
                $uids[$k] = intval($v);
            }
            if (!$uids) {
                $this->error('参数错误！');
                $uids = implode(',', $uids);
            }
        }
        $where['id'] = array('in', $uids);
        if(M('LbPicture')->where($where)->delete()){
            $this->success('删除成功');
        }else{
            $this->error('操作异常');
        }
    }
}